<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    .container{
        width: 800px;
        margin: 0 auto;
        display: flex;
    }
    .todo, .done{
        width: 50%;
        height: 100%;
    }
    .container h3 {
        height: 50px;
        text-align: center;
        line-height: 50px;
        background-color: #333;
        color: #fff;
    }
    .nav {
        width: 800px;
        height: 100px;
        margin: 0 auto;
        display: flex;
        align-items: center;
    }
    .nav input {
        width: 600px;
        height: 50px;
    }
    .nav button {
        width: 200px;
        height: 50px;
        border: none;
        background-color: orange;
        color: #fff;
    }
    .nav button:active {
        background-color: green;
    }
    .row {
        height: 50px;
        display: flex;
        align-items: center;
    }
    .row input {
        margin: 0 10px;
    }
    .row span {
        width: 300px;
    }
    .row button {
        width: 50px;
        height: 40px;
    }
</style>
<body>
    <div class="nav">
        <input type="text">
        <button>新建任务</button>
    </div>
    <div class="container">

        <div class="todo">
            <h3>未完成</h3>
<!--            <div class="row"> </div>-->
        </div>

        <div class="done">
            <h3>已完成</h3>
        </div>

    </div>
</body>
<script>
    var addTaskButton = document.querySelector('.nav button');
    addTaskButton.onclick = function () {
        // 1. 获取任务输入框
        var input = document.querySelector('.nav input');
        if(input.value == ''){
            alert('啥也木写');
            return;
        }
        // 2. 获取到输入框内容
        var taskContent = input.value;
        // 3. 根据内容新建元素
        var row = document.createElement("div");
        row.className = 'row';
        var checkbox = document.createElement("input");
        checkbox.type = 'checkbox';
        var span = document.createElement("span");
        span.innerText = taskContent;
        var button = document.createElement("button");
        button.innerText = '删除';

        row.appendChild(checkbox);
        row.appendChild(span);
        row.appendChild(button);
        // 4. 插入
        var todo = document.querySelector('.todo');
        todo.appendChild(row);
        // 5. 清空输入框
        input.value = '';
        // 6. 给checkbox注册点击事件
        checkbox.onclick = function () {
            var row = this.parentNode;
            if(this.checked) {
                var target = document.querySelector('.done');
            }
            else{
                var target = document.querySelector('.todo');
            }
            target.appendChild(row);
        }
        // 7. 注册删除事件
        button.onclick = function () {
            var row = this.parentNode;
            var grandParent = row.parentNode;
            grandParent.removeChild(row);
        }
    }
</script>
</html>


